//
//  OrderView.m
//  OrderSureDemo
//
//  Created by WillyZhao on 2017/6/12.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "OrderView.h"

@interface OrderView () {
    //底部主视图
    UIView *homeBgView;
    
    //收件人
    UILabel *personOwner;
    
    //收货地址
    UILabel *addressOwner;
    
    //电话号码
    UILabel *phoneNoOwner;
    
    //选择地址跳转
    UIButton *toAddressBtn;
    
    
    //
    //商品图片
    UIImageView *goodIMG;
    
    //商品名称
    UILabel *goodName;
    
    //商品尺码
    UILabel *goodSize;
    
    //商品价格
    UILabel *goodPrice;
    
    //商品数量
    UILabel *goodCount;
    
    //商品颜色
    UILabel *goodColor;
    
    
    //
    //配送方式
    UILabel *distributionStyle;
    
    //配送时间
    UILabel *distributionTime;
    
    
    //
    //发票信息
    UILabel *invoiceDesc;
    
    //优惠卡
    UILabel *IntroducingDesc;
    
    
    //
    //总积分/运费
    UILabel *totalPrices;
    
    //运费，可不管
    
    
    //
    //立即支付按钮
    UIButton *immediateBtn;
}

@end

@implementation OrderView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubViews:frame];
    }
    return self;
}

- (void)setOrderWithAddress:(NSString *)address recipient:(NSString *)recipient phone:(NSString *)phone {

    if (address.length == 0) {
        
        addressOwner.text = @"四川成都";
        phoneNoOwner.text = @"";
        personOwner.text = @"";
        return;
    }
    addressOwner.text = address;
    phoneNoOwner.text = phone;
    personOwner.text = recipient;
}

-(void)initializeSubViews:(CGRect)frame {
    
    homeBgView = [[[NSBundle mainBundle] loadNibNamed:@"sureOrder" owner:self options:nil]firstObject];
    homeBgView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
    homeBgView.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    [self addSubview:homeBgView];
    
    //初始化
    personOwner = (UILabel *)[homeBgView viewWithTag:101];
    
    addressOwner = (UILabel *)[homeBgView viewWithTag:102];
    
    phoneNoOwner = (UILabel *)[homeBgView viewWithTag:103];
    
    toAddressBtn = (UIButton *)[homeBgView viewWithTag:104];
    [toAddressBtn addTarget:self action:@selector(toAddressBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    goodIMG = (UIImageView *)[homeBgView viewWithTag:105];
    
    goodName = (UILabel *)[homeBgView viewWithTag:106];
    
    goodPrice = (UILabel *)[homeBgView viewWithTag:107];
    
    goodSize = (UILabel *)[homeBgView viewWithTag:108];
    
    goodCount = (UILabel *)[homeBgView viewWithTag:109];
    
    goodColor = (UILabel *)[homeBgView viewWithTag:110];
    
    
    distributionStyle = (UILabel *)[homeBgView viewWithTag:111];
    
    distributionTime = (UILabel *)[homeBgView viewWithTag:112];
    UIButton *distriBtn = (UIButton *)[homeBgView viewWithTag:1002];
    [distriBtn addTarget:self action:@selector(distributeBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    invoiceDesc = (UILabel *)[homeBgView viewWithTag:113];
    
    IntroducingDesc = (UILabel *)[homeBgView viewWithTag:114];
    UIButton *introBtn = (UIButton *)[homeBgView viewWithTag:1001];
    [introBtn addTarget:self action:@selector(preferentialBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    totalPrices = (UILabel *)[homeBgView viewWithTag:115];
    
    
    immediateBtn = (UIButton *)[homeBgView viewWithTag:117];
    [immediateBtn addTarget:self action:@selector(immidateBtn:) forControlEvents:UIControlEventTouchUpInside];
    immediateBtn.backgroundColor = YBKRGBCOLOR(240, 96, 96, 1);
}

- (void)setDataDic:(NSDictionary *)dataDic {

    _dataDic = dataDic;
    if (dataDic) {
        
        goodName.text = [NSString stringWithFormat:@"%@",[dataDic objectForKey:@"name"]];
        if (![PublicFunction isNull:[dataDic objectForKey:@"size"]]) {
         
            goodSize.text = [NSString stringWithFormat:@"尺寸:%@",[dataDic objectForKey:@"size"]];
        }
        else {
        
            goodSize.text = @"尺寸:默认";
        }
        if (![PublicFunction isNull:[dataDic objectForKey:@"color"]]) {
            
            goodColor.text = [NSString stringWithFormat:@"颜色:%@",[dataDic objectForKey:@"color"]];
        }
        else {
        
            goodColor.text = @"颜色:默认";
        }
        goodCount.text = [NSString stringWithFormat:@"x%@",[dataDic objectForKey:@"sum"]];
        goodPrice.text = [NSString stringWithFormat:@"积分:%@.00",[dataDic objectForKey:@"price"]];
        [goodIMG sd_setImageWithURL:[NSURL URLWithString:[dataDic objectForKey:@"image"]] placeholderImage:nil];
        NSInteger count = [[dataDic objectForKey:@"sum"] integerValue];
        NSInteger price = [[dataDic objectForKey:@"price"] integerValue];
        totalPrices.text = [NSString stringWithFormat:@"总积分:%ld",count*price];
    }
}

-(void)toAddressBtn:(UIButton *)btn {
    //地址选取
    if (self.ad_clicked) {
        self.ad_clicked();
    }
}

-(void)immidateBtn:(UIButton *)btn {
    //立即支付
    if (self.im_clicked) {
        self.im_clicked(@"立即支付");
    }
}

-(void)distributeBtn:(UIButton *)btn {
    //配送方式
    if (self.di_clicked) {
        self.di_clicked();
    }
}

-(void)preferentialBtn:(UIButton *)btn {
    //积分卡
    if (self.pr_clicked) {
        self.pr_clicked();
    }
}

@end
